package com.example.springboot.mapper.blog.service.serviceImp;

import com.example.springboot.entity.Blog;
import com.example.springboot.mapper.blog.mapper.BlogMapper;
import com.example.springboot.mapper.blog.service.BlogService;
import com.github.pagehelper.PageHelper;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;

/**
 * @param
 * @Description: 类描述
 * @Author: allan5945@qq.com
 * @Date: 2018/10/24
 * @return:
 * @throws:
 */
@Service("BlogServiceImp")
public class BlogServiceImp implements BlogService {

    @Autowired
    private  BlogMapper blogMapper;


    @Override
    public List<Blog> selectHotBlog(Integer pageNum, Integer pageSize, ArrayList<String> con) {
        PageHelper.startPage(pageNum,pageSize);
        List<Blog> list = blogMapper.selectHotBlog(con);
        PageHelper.clearPage();
        return list;
    }

    @Override
    public Blog selectBlog(Integer id) {
        return blogMapper.selectBlog(id);
    }

    @Override
    public Integer blogeCount(ArrayList<String> con) {
        List<Blog> list = blogMapper.selectHotBlog(con);
        return list.size();
    }

    @Override
    @Transactional
    public Boolean addBlog(Blog blog) {
        return blogMapper.addBlog(blog);
    }

    @Override
    @Transactional
    public Boolean delectBlog(Integer id,Integer userId) {
        return blogMapper.delectBlog(id,userId);
    }

    @Override
    public List<String> getHotTag(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        return blogMapper.getHotTag();
    }
    public List<String> getTag(Integer userId) {
        return blogMapper.getTag(userId);
    }

    @Override
    public List<Blog> selectUserBlog(Integer belongerId) {
        return blogMapper.selectUserBlog(belongerId);
    }

}
